package com.rongc.client.freight.business.supply.view.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.rongc.client.core.utils.ActivityUtils;
import com.rongc.client.core.utils.StringUtils;
import com.rongc.client.freight.ApiUrl;
import com.rongc.client.freight.R;
import com.rongc.client.freight.base.BaseFragment;
import com.rongc.client.freight.base.view.widget.BGASortableNinePhotoLayoutView;
import com.rongc.client.freight.business.carrier.model.ConveyanceBean;
import com.rongc.client.freight.business.mine.model.CarBean;
import com.rongc.client.freight.business.supply.view.activity.ComplaintsActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;
import cn.bingoogolapple.photopicker.activity.BGAPhotoPreviewActivity;

/**
 * Created by Bruce on 2017/07/14.
 */
public class SupplyDetailFragment extends BaseFragment implements
        View.OnClickListener,
        BGASortableNinePhotoLayoutView.Delegate{
    @Bind(R.id.tv_detail_date)
    TextView mTvDate;
    @Bind(R.id.tv_detail_plateno)
    TextView mTvPlateno;
    @Bind(R.id.tv_detail_model)
    TextView mTvModel;
    @Bind(R.id.tv_detail_dilk)
    TextView mTvDulk;
    @Bind(R.id.tv_detail_message)
    TextView mTvMessage;

    @Bind(R.id.plv_clxq)
    BGASortableNinePhotoLayoutView ninePhotoLayout;
    ArrayList<String> selectedPhotos = new ArrayList<>();

    String sourceId;
    String fk_id;

    public static SupplyDetailFragment getInstance(){
        SupplyDetailFragment fragment = new SupplyDetailFragment();
        Bundle bdl = new Bundle();
//        bdl.putString("orderType", orderType);
        fragment.setArguments(bdl);
        return fragment;
    }

    public void setData(ConveyanceBean conveyanceBean,CarBean carBean){
        mTvDate.setText(conveyanceBean.getLoadTime());
        mTvPlateno.setText(carBean.getPlateno());
        mTvModel.setText(StringUtils.getNewModel(getActivity(), carBean.getLength(), carBean.getCarLoad(), carBean.getDulk(), carBean.getModel()));
        mTvDulk.setText(carBean.getCarLoad());
        mTvMessage.setText(conveyanceBean.getMessage());

        sourceId = conveyanceBean.getId();
        fk_id = carBean.getUserId();
    }

    public void setCar(CarBean carBean){
        findViewById(R.id.lyt_clxq).setVisibility(View.VISIBLE);
        selectedPhotos = new ArrayList<>();
        if(StringUtils.isNotEmpty(carBean.getImg2()))
            selectedPhotos.add(ApiUrl.getCarImgUrl(carBean.getImg2()));
        if(StringUtils.isNotEmpty(carBean.getImg3()))
            selectedPhotos.add(ApiUrl.getCarImgUrl(carBean.getImg3()));
        if(StringUtils.isNotEmpty(carBean.getImg4()))
            selectedPhotos.add(ApiUrl.getCarImgUrl(carBean.getImg4()));
        ninePhotoLayout.setData(selectedPhotos);
    }

    @OnClick({R.id.tv_complaints})
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_complaints:
                Bundle bundle = new Bundle();
                bundle.putString("sourceId",sourceId);
                bundle.putString("fk_id",fk_id);
                ActivityUtils.startActivity(getActivity(), ComplaintsActivity.class,bundle);
                break;
        }
    }

    @Override
    public void initData() {
    }

    @Override
    public void initListener() {

    }


    @Override
    public void initView() {
        ninePhotoLayout.init(getActivity());
        ninePhotoLayout.setDelegate(this);
    }


    @Override
    public void onClickNinePhotoItem(BGASortableNinePhotoLayoutView ninePhotoLayout, View view, int position, String model, List<String> models) {
        startActivity(BGAPhotoPreviewActivity.newIntent(getActivity(), null, (ArrayList<String>) models, position));
    }

    @Override
    public boolean onLongClickNinePhotoItem(BGASortableNinePhotoLayoutView ninePhotoLayout, View view, int position, String model, List<String> models) {
        return false;
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_conveyance_detail;
    }
}
